HUGO
Menu
GitHub 90386 stars Mastodon

RSS templates

Use the embedded RSS template, or create your own.

Configuration

By default, when you build your project, Hugo generates RSS feeds for home, section, taxonomy, and term pages. Control feed generation in your project configuration. For example, to generate feeds for home and section pages, but not for taxonomy and term pages:

outputs:
  home:
  - html
  - rss
  section:
  - html
  - rss
  taxonomy:
  - html
  term:
  - html
[outputs]
  home = ['html', 'rss']
  section = ['html', 'rss']
  taxonomy = ['html']
  term = ['html']
{
   "outputs": {
      "home": [
         "html",
         "rss"
      ],
      "section": [
         "html",
         "rss"
      ],
      "taxonomy": [
         "html"
      ],
      "term": [
         "html"
      ]
   }
}

To disable feed generation for all page kinds:

disableKinds:
- rss
disableKinds = ['rss']
{
   "disableKinds": [
      "rss"
   ]
}

By default, the number of items in each feed is unlimited. To limit the number of items, change your project configuration:

services:
  rss:
    limit: 42
[services]
  [services.rss]
    limit = 42
{
   "services": {
      "rss": {
         "limit": 42
      }
   }
}

Set limit to -1 to generate an unlimited number of items per feed.

The embedded RSS template renders these values from your project configuration, if present:

copyright: © 2023 ABC Widgets, Inc.
params:
  author:
    email: jdoe@example.org
    name: John Doe
copyright = '© 2023 ABC Widgets, Inc.'
[params]
  [params.author]
    email = 'jdoe@example.org'
    name = 'John Doe'
{
   "copyright": "© 2023 ABC Widgets, Inc.",
   "params": {
      "author": {
         "email": "jdoe@example.org",
         "name": "John Doe"
      }
   }
}

Include feed reference

To include a feed reference in the head element of your rendered pages, place this within the head element of your templates:

{{ with .OutputFormats.Get "rss" }}
  {{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink site.Title | safeHTML }}
{{ end }}

Hugo renders this to:

<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml" title="ABC Widgets">

Override the embedded template

Override Hugo’s embedded RSS template by creating one or more of your own. Hugo selects RSS templates using the template lookup order. To use one template for all feeds, create layouts/rss.xml. To use different templates for home, section, taxonomy, and term pages, create these templates:

layouts/
├── home.rss.xml
├── section.rss.xml
├── taxonomy.rss.xml
└── term.rss.xml

RSS templates receive a Page object in context.